package com.ky.user.strategy;


import com.ky.common.param.MqMsg;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
 * --- 天道酬勤 ---
 *
 * @author 1379
 * @date 2024/6/5
 * @desc -- 代码敲烂 月薪过万--
 */
@Service
public class StrategyFactory {


    private final List<AbstractStrategy> abstractStrategies;

    public StrategyFactory(List<AbstractStrategy> abstractStrategies){
        this.abstractStrategies = abstractStrategies;
    }

    private Map<Integer,AbstractStrategy> map = new ConcurrentHashMap<>();


    @PostConstruct
    public void init(){
        Optional.ofNullable(abstractStrategies).orElseGet(ArrayList::new).forEach(strategy ->{
            map.put(strategy.getType(),strategy);
        });

    }

    public void doMqMsg(MqMsg msg){
        map.get(msg.getType()).doMqMsg(msg);
    }

}
